// pages/fans/Collection.js
let axios = require("../../utils/util.js")
import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
Page({
  data: {
    page: 1,
    collectRoom_data: true, //还有数据
    collectRoom: [],
    loading: false,
  },
  fui_() {
    wx.navigateBack({ //返回
      delta: 1
    })
  },
  query_dedlt(room_id) {
    let params = {
      roomId: room_id,
      type: '2'
    };
    axios.axios({
      url: "/chat/follow_room",
      data: params
    }).then((res) => {
      if (res.data.status == 0) {
        this.Collection()
      }
      wx.showToast({
        title: res.data.text,
        icon: 'none',
        duration: 2000
      })
    })
  },
  dedet(data) {
    let list_ = data.currentTarget.dataset.list_
    let that = this;
    Dialog.confirm({
        message: `确定删除${list_.name}房间吗？`,
        confirmButtonColor: '#0091FF',
        cancelButtonColor: '#999999',
      })
      .then(() => {
        that.query_dedlt(list_.room_id)
      })
      .catch(() => {
        // on cancel
      });

  },
  join_room(data) {
    let roomid = data.currentTarget.dataset.roomid
    console.log(roomid);
    wx.navigateTo({
      url: '/pages/room/room?roomId=' + roomid,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  Collection() {
    let params = {
      page: this.data.page
    };
    axios.axios({
      url: "/index/collectRoom",
      data: params
    }).then((res) => {
      this.setData({
        collectRoom: res.data.result.room_list,
      })
    })
  },
  onLoad: function (options) {
    this.Collection()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.collectRoom_data) {
      this.data.page++
      this.setData({
        page: this.data.page,
        loading: true,
      })
      this.onReach_collectRoom()
    }
  },
  onReach_collectRoom() {
    let params = {
      page: this.data.page
    };
    axios.axios({
      url: "/index/collectRoom",
      data: params
    }).then((res) => {
      if (res.data.status == 0) {
        if (res.data.result.room_list.length > 0) {
          let a = this.data.collectRoom;
          let b = res.data.result.room_list
          let c = a.concat(b);
          this.setData({
            collectRoom_data: true,
            loading: false,
            collectRoom: c,
          })
        }else {
            this.setData({
              loading: false,
              collectRoom_data: false,
            })
            wx.showToast({
              title: "没有更多",
              icon: 'none',
              duration: 2000 //持续的时间
            })
        }
      }

    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
